package com.demo.webservicedemo.mapper;


import com.demo.webservicedemo.entity.MaterialEntry;
import org.apache.ibatis.annotations.*;

@Mapper
public interface MaterialEntryMapper {

    @Insert("INSERT INTO material_entry(order_id, material, batch, plant, entry_qnt) " +
            "VALUES(#{orderId}, #{material}, #{batch}, #{plant}, #{entryQnt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(MaterialEntry entry);

    @Update("UPDATE material_entry SET " +
            "entry_qnt = #{entryQnt}, " +
            "material = #{material}, " +
            "batch = #{batch}, " +
            "plant = #{plant}, " +
            "update_time = NOW() " +
            "WHERE order_id = #{orderId}")
    int update(MaterialEntry entry);

    @Delete("DELETE FROM material_entry WHERE id = #{id}")
    int delete(Integer id);

    @Select("SELECT * FROM material_entry WHERE id = #{id}")
    MaterialEntry selectById(Integer id);

    // 根据唯一索引查询
    @Select("SELECT * FROM material_entry " +
            "WHERE order_id = #{orderId} "
            )
    MaterialEntry selectByUniqueKey(
            @Param("orderId") String orderId
           );
}